(function(host, name){

var util = '$$$util$$$' in this ? this['$$$util$$$'] : require('./libra.util');
var Model = util.using('model');

var ModelPromise = Model.Class('ModelPromise', function(){
	this.$resolve = function(data){ this.put(data); }.bind(this);
	this.$reject = function(data){ this.put(data); }.bind(this);
}, {
	invoke: function(async, args){
		var promise = util.createPromise(async, args);
		promise.then(this.$resolve, this.$reject);
	}
});

ModelPromise.create = function(schema, fn){
	var m = new ModelPromise(schema);
	if(util.isArray(schema) && util.isFunction(fn)){
		m.defineGetter(schema, fn);
	}
	return m;
};
ModelPromise.Class = function(name, construct, protos){
	return util.Class(name, ModelPromise, construct, protos);
};

util.regist(host, name, ModelPromise);


})(this, 'model.promise');
